import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { DICT_TYPE } from '@vben/constants';

import { getRangePickerDefaultProps } from '#/utils';

import { $t } from '#/locales';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: $t('views.bpm.task.common.taskName'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.bpm.task.common.taskNamePlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'createTime',
      label: $t('common.createTime'),
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'processInstance.name',
      title: $t('views.bpm.task.common.processName'),
      minWidth: 200,
      fixed: 'left',
    },
    {
      field: 'processInstance.startUser.nickname',
      title: $t('views.bpm.task.common.startUser'),
      minWidth: 120,
    },
    {
      field: 'name',
      title: $t('views.bpm.task.common.currentTask'),
      minWidth: 180,
    },
    {
      field: 'createTime',
      title: $t('views.bpm.task.common.taskStartTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'endTime',
      title: $t('views.bpm.task.common.taskEndTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'assigneeUser.nickname',
      title: $t('views.bpm.task.common.assigneeUser'),
      minWidth: 180,
    },
    {
      field: 'status',
      title: $t('views.bpm.task.common.taskStatus'),
      minWidth: 180,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.BPM_TASK_STATUS },
      },
    },
    {
      field: 'reason',
      title: $t('views.bpm.task.common.reason'),
      minWidth: 180,
    },
    {
      field: 'durationInMillis',
      title: $t('views.bpm.task.common.durationInMills'),
      minWidth: 180,
      formatter: 'formatPast2',
    },
    {
      field: 'processInstanceId',
      title: $t('views.bpm.task.common.processInstanceId'),
      minWidth: 280,
    },
    {
      field: 'id',
      title: $t('views.bpm.task.common.taskId'),
      minWidth: 280,
    },
    {
      title: $t('common.action'),
      width: 120,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
